package es.ats.codington.festival.services;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import es.ats.codington.festival.daos.EventDAOImp;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.exceptions.ServiceException;
import es.ats.codington.festival.interfaces.services.IEventService;
import es.ats.codington.festival.utils.FERSDataConnection;


public class EventService implements IEventService {
	private EventDAOImp edi;
	private Event ev;
	

	public EventService() {
		super();
		edi=new EventDAOImp();
		ev=new Event();
	}

	public EventService(EventDAOImp edi, Event ev) {
		super();
		this.edi = edi;
		this.ev = ev;
	}

	public EventDAOImp getEdi() {
		return edi;
	}

	public void setEdi(EventDAOImp edi) {
		this.edi = edi;
	}

	public Event getEv() {
		return ev;
	}

	public void setEv(Event ev) {
		this.ev = ev;
	}

	@Override
	public Event getEventById(int eventId) throws ServiceException{
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			ev=edi.getEventById(eventId);
			fdc.disconnect();
			return ev;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int insertEvent(Event event) throws ServiceException{
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int id=edi.insertEvent(event);
			fdc.disconnect();
			return id;
		}
		catch (Exception ex) {
			throw new ServiceException("Service insertEvent failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int deleteEventById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int id=edi.deleteEventById(eventId);
			fdc.disconnect();
			return id;
		}
		catch (Exception ex) {
			throw new ServiceException("Service insertEvent failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int checkEventSeatsAvailableById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.checkEventSeatsAvailableById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventSeatsAvailableById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public String checkEventNameById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			String s=edi.checkEventNameById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventNameById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public String checkEventDescriptionById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			String s=edi.checkEventDescriptionById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventDescriptionById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public Date checkEventStartById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			Date s=edi.checkEventStartById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventStartById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int checkEventDurationById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.checkEventDurationById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventDurationById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public Float checkEventPriceById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			Float s=edi.checkEventPriceById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventPriceById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int checkEventPlaceById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.checkEventPlaceById(eventId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventPlaceById failure:"+ex.getMessage(), ex);
		}
	}
	
	@Override
	public int checkPhotoById(int eventId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int img=edi.checkPhotoById(eventId);
			fdc.disconnect();
			return img;
		}
		catch (Exception ex) {
			throw new ServiceException("Service checkEventPlaceById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventNameById(int eventId, String name) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventNameById(eventId,name);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventNameById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventDescriptionById(int eventId, String description) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventDescriptionById(eventId,description);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventDescriptionById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventStartById(int eventId, Date start) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventStartById(eventId,start);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventStartById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventDurationById(int eventId, int duration) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventDurationById(eventId,duration);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventDurationById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventPriceById(int eventId, Float price) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventPriceById(eventId,price);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventPriceById failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public int updateEventPlaceById(int eventId, int placeId) {
		FERSDataConnection fdc=edi.getCon();
		try{
			fdc.connect();
			int s=edi.updateEventPlaceById(eventId,placeId);
			fdc.disconnect();
			return s;
		}
		catch (Exception ex) {
			throw new ServiceException("Service updateEventPlaceById failure:"+ex.getMessage(), ex);
		}
	}
	
	@Override
	public List<Event> getAllEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getAllEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getAllEvents failure:"+ex.getMessage(), ex);
		}
	}
	
	@Override
	public List<Event> getEventsByName(String eventName) throws ServiceException{
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByName(eventName);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByName failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getEventsByDescription(String description) throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByDescription(description);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByDescription failure:"+ex.getMessage(), ex);
		}
	}
	
	@Override
	public List<Event> getEventsByNameOrDescription(String s) throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByNameOrDescription(s);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByNameOrDescription failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getEventsByPlaceId(int placeId) throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByPlaceId(placeId);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByPlaceId failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getEventsByPlaceType(int type) throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByPlaceType(type);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByPlaceType failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getBusinessEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getBusinessEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getBusinessEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getMarketEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getMarketEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getmarketEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getMuseumEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getMuseumEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getMuseumEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getParkEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getParkEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getParkEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getStadiumEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getStadiumEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getStadiumEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getTheaterEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getTheaterEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getTheaterEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getTouristEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getTouristEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getTouristEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getZooEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getZooEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getZooEvents failure:"+ex.getMessage(), ex);
		}
	}
	
	@Override
	public List<Event> getEventsByZone(int zone) throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getEventsByZone(zone);
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getEventsByZone failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getNorthEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getNorthEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getNorthEvents failure:"+ex.getMessage(), ex);
		}
	}

	@Override
	public List<Event> getSouthEvents() throws ServiceException {
		FERSDataConnection fdc=edi.getCon();
		List<Event> events = new ArrayList<Event>();
		try{
			fdc.connect();
			events=edi.getSouthEvents();
			fdc.disconnect();
			return events;
		}
		catch (Exception ex) {
			throw new ServiceException("Service getSouthEvents failure:"+ex.getMessage(), ex);
		}
	}
	

	
}
